package test_mongo

import (
	"fmt"
	"labix.org/v2/mgo"
	"labix.org/v2/mgo/bson"
)

type Student struct {
	ID int `bson:"_id"`
	Name string `bson:"sname"`
	Age int `bson:"sage"`
}

func Do()  {
	session, err := mgo.Dial("47.241.180.222:27017")//要连接的服务器和端口
	if err != nil {
		panic(err)
	}
	defer session.Close()
	//获取数据库，获取集合
	c := session.DB("school").C("student")
	result := Student{}
	err = c.Find(bson.M{"_id":2}).One(&result)
	if err != nil {
		panic(err)
	}
	//for _, i2 := range result {
		fmt.Println("momgo-test:", result)
	//}
}